<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-tabs>
        <el-tab-pane label="登录账户设置">
          <el-form ref="userForm" label-width="120px" style="margin-left:120px;margin-top:30px">
            <el-form-item label="姓名" prop="username">
              <el-input v-model="userInfo.username" style="width:300px" />
            </el-form-item>
            <el-form-item label="密码" prop="password2">
              <el-input v-model="userInfo.password2" style="width:300px" type="password" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="saveUser">更新</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情">
          <user-info />
        </el-tab-pane>
        <el-tab-pane label="岗位信息">
          <job-info />
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
import { getUserDetailByid } from '@/api/user'
import { saveUserDetailById } from '@/api/employeement'
import userInfo from '@/views/employees/components/user-info.vue'
import jobInfo from '@/views/employees/components/job-info.vue'
export default {
  components: {
    userInfo,
    jobInfo
  },
  data() {
    return {
      userId: this.$route.params.id,
      userInfo: {},
      rules: {
        username: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
        password2: [{ required: true, message: '密码不能为空', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.getUserDetailByid()
  },
  methods: {
    async getUserDetailByid() {
      this.userInfo = await getUserDetailByid(this.userId)
    },
    async saveUser() {
      try {
        await this.$refs.userForm.validate()
        await saveUserDetailById({ ...this.userInfo, password: this.userInfo.password2 })
        this.$message.success('保存成功')
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>

<style>

</style>
